package com.jeeplus.modules.guide.task;

import com.jeeplus.modules.guide.service.RongYiBanService;
import com.jeeplus.modules.guide.utils.RongYiBanOkHttpUtil;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class RongYiBan {
    @Autowired
    private RongYiBanService rongYiBanService;

    //蓉易办-排队叫号-区县上传取号数据
    @Value("${GetNumber}")
    private String GetNumber;
    //蓉易办-排队叫号-区县取号办理信息上传
    @Value("${HandleInfoUp}")
    private String HandleInfoUp;
    //高新行政区划代码
    private String AreaCode="510109";
    //蓉易办对接Appkey
    @Value("${AppKey}")
    private String AppKey;

    private static final Logger logger = LoggerFactory.getLogger(ManageDuration.class);

    public void RongYiBanQH(){
        List<String> valueList = new ArrayList<String>();
        List<Map<String, String>> list = rongYiBanService.toDayTakeNumber();
        for (int i = 0; i < list.size(); i++) {
            Map<String, String> map = list.get(i);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("qno",getJCNumber(map.get("sysno"),map.get("qno")));
            jsonObject.put("identitycardnum", map.get("identitycardnum"));
            jsonObject.put("areacode", AreaCode);
            jsonObject.put("tasktypeguid", AreaCode + map.get("tasktypeguid"));
            logger.error("定时蓉易办-排队叫号-区县取号信息上传:" + map.get("qno") + ":" + jsonObject.toString());
            String data = RongYiBanOkHttpUtil.getData(AppKey, GetNumber, jsonObject.toString());
            logger.error("定时蓉易办-排队叫号-区县取号信息上传接口返回:" + map.get("qno") + ":" + data);
            valueList.add(map.get("id"));
        }
        if(valueList.size() >= 1)
        rongYiBanService.updateBak("1",valueList);
    }
    public void RongYiBanJH(){
        List<String> valueList = new ArrayList<String>();
        List<Map<String, String>> list = rongYiBanService.toDayCallNumber();
        for (int i = 0; i < list.size(); i++) {
            Map<String, String> map = list.get(i);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("iscall",1);
            jsonObject.put("areacode",AreaCode);
            jsonObject.put("tasktypeguid",AreaCode+map.get("tasktypeguid"));
            jsonObject.put("qno",getJCNumber(map.get("sysno"),map.get("qno")));
            logger.error("定时蓉易办-排队叫号-区县叫号信息上传:"+map.get("qno")+":"+jsonObject.toString());
            String data = RongYiBanOkHttpUtil.getData(AppKey, HandleInfoUp, jsonObject.toString());
            logger.error("定时蓉易办-排队叫号-区县叫号信息上传接口返回:"+map.get("qno")+":"+data);
            valueList.add(map.get("id"));
        }
        if(valueList.size() >= 1)
            rongYiBanService.updateBak("2",valueList);

    }
    public void RongYiBanBJ(){
        List<String> valueList = new ArrayList<String>();
        List<Map<String, String>> list = rongYiBanService.toDayFinishNumber();
        for (int i = 0; i < list.size(); i++) {
            Map<String, String> map = list.get(i);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("iscall",2);
            jsonObject.put("areacode",AreaCode);
            jsonObject.put("tasktypeguid",AreaCode+map.get("tasktypeguid"));
            jsonObject.put("qno",getJCNumber(map.get("sysno"),map.get("qno")));
            logger.error("定时蓉易办-排队叫号-区县办结信息上传:"+map.get("qno")+":"+jsonObject.toString());
            String data = RongYiBanOkHttpUtil.getData(AppKey, HandleInfoUp, jsonObject.toString());
            logger.error("定时蓉易办-排队叫号-区县办结信息上传接口返回:"+map.get("qno")+":"+data);
            valueList.add(map.get("id"));
        }
        if(valueList.size() >= 1)
            rongYiBanService.updateBak("3",valueList);
    }
    public String getJCNumber(String sysno,String qno){
        String jc = rongYiBanService.getJC(sysno);

       return jc+qno;
    }
}
